package game_FrozenBubble;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;

import com.gmsi_prototype.R;

public class OptionsActivity extends Activity {

	public boolean musicOn = true;
	public boolean soundOn = true;
	public boolean fileExist = true; // check to see if file exist some how
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game_activity_options);

        //Floating Animation
        Animation floatingM = AnimationUtils.loadAnimation(this, R.anim.floating);
        Animation floatingS = AnimationUtils.loadAnimation(this, R.anim.floating);
        Animation floatingD = AnimationUtils.loadAnimation(this, R.anim.floating);
        Animation floatingSen = AnimationUtils.loadAnimation(this, R.anim.floating);
        Animation floatingT = AnimationUtils.loadAnimation(this, R.anim.floating);
        
        //Music Button        
        final Button music = (Button)findViewById(R.id.musicButton);
        music.startAnimation(floatingM);
        
        music.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {            
            	
            	if(musicOn){
            		musicOn = false;
            		
            		music.setBackgroundResource(R.drawable.music_off);
            	}
            	else{
            		musicOn = true;
            		music.setBackgroundResource(R.drawable.music_on);
            	}
           
            }
        });
        
        //Sound Button        
        final Button sound = (Button)findViewById(R.id.soundButton);
        floatingS.setStartOffset(200);
        sound.startAnimation(floatingS);
        
        sound.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {            
            	
            	if(soundOn){
            		soundOn=false;
            		//FrozenBubble.setSoundOn(false);
            		sound.setBackgroundResource(R.drawable.sound_off);
            	}
            	else{
            		soundOn = true;
            		//FrozenBubble.setSoundOn(true);
            		sound.setBackgroundResource(R.drawable.sound_on);
            	}
           
            }
        });
        
        // Sensor 
        final Button btSensor = (Button) findViewById(R.id.sensorButton);
        floatingSen.setStartOffset(100);
        btSensor.startAnimation(floatingSen);
        
        btSensor.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent sensor_selection_activity = new Intent(OptionsActivity.this, SensorSelectionActivity.class);
				startActivity(sensor_selection_activity);
				finish();
			}
		});
        
        final Button bToThreshold = (Button) findViewById(R.id.btToThreshold);
        floatingT.setStartOffset(150);
        bToThreshold.startAnimation(floatingT);
		bToThreshold.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent thresholdActivity = new Intent(OptionsActivity.this, ThresholdActivity.class);
				startActivity(thresholdActivity);
				finish();
				
			}
		});

        
        // Back to Start Screen 
        final Button btBackToStart = (Button) findViewById(R.id.btBackToStart);
        btBackToStart.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent game_start_activity = new Intent(OptionsActivity.this, ChillOut.class);
				startActivity(game_start_activity);
				finish();
			}
		});
        
//        //Delete Button Disable         
//        final Button delete = (Button)findViewById(R.id.deleteButton);
//        floatingD.setStartOffset(400);
//        delete.startAnimation(floatingD);
//        File file = getFileStreamPath("calibration.txt");
//        
//        if(file.exists()){
//        	fileExist = true;
//        	delete.setBackgroundResource(R.drawable.delete);
//        }
//        else {
//        	fileExist = false;
//        	delete.setBackgroundResource(R.drawable.delete2);
//        }
//        
//        delete.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View v) {
//            	
//            	if(fileExist){
//            		fileExist = false;
//            		
//            		delete.setBackgroundResource(R.drawable.delete2);  
//            		
//            		// Delete previous calibration file
//            		deleteFile("calibration.txt");
//            	}
//
//           
//            }
//        });
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if ((keyCode == KeyEvent.KEYCODE_BACK))
        {
        	finish();
        	
        	//Attempting to go back to the Title Screen
			Intent title_intent = new Intent(OptionsActivity.this, ChillOut.class);
			startActivity(title_intent);

        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onBackPressed() {
    }

}
